import React from 'react';
import { ts2Formatter,renderState } from 'utils';
import moment from 'moment';
import { actions } from 'mirrorx';
{/*
可配置化种类：

1、表格头部字段 
    1、列表页表格头部字段集合 mainTableColumn
    2、编辑页表格头部字段集合 childTableColumn

2、编辑框的字段
    1、编辑页 直接显示在页面的编辑字段 FormField
    2、编辑页 需要点击表格的增行弹框编辑的字段 FormTableField
    3. 列表页查询区域  searchField

3.表头部的按钮  headerButtonSets

4.表行尾部按钮  columnButtonSets
*/}

//表头信息

//字段属性

//基本信息
const FormDataHeader = [
    {
        enname: "code",
        zhname: "单据号",
        type: "FormControl",
        hidepage:{0:true},
        edit: false,
    },
    {
        enname: "policytypeId",
        showname: "policytypeName",
        codename: "policytypeCode",
        zhname: "政策类型",
        type: "Select",
        code:"ZCLX",
        edit: true,
        required: true,
    },
    {
        enname: "billStatusId",
        codename: "state",
        showname: "billStatusName",
        zhname: "审批状态",
        type: "Select",
        hidepage: { 0: true },
        code: "BILL_STATUS",
        required: false,
        edit: false,
    },
    {
        enname: "branchbfficeId",
        showname: "branchbfficeName",
        codename: "branchbfficeCode",
        zhname: "所属组织",
        type: "RefComponent",
        refname:"organization",
        cascadeChildTable:[{
            refKey: "refpk", 
            dtoKey: "branchbfficeId",
            childType:"commissionSon" 
        }],
        param:{
            "AUTH_refdim":"branchbffice","AUTH_refcod":"promotercommission"
        },
        edit: true,
        required: true,
    },
    {
        enname: "startdate",
        zhname: "生效日期",
        type: "DatePicker",
        format:"YYYY-MM-DD",
        edit: true,
        required: false,
    },
    {
        enname: "enddate",
        zhname: "截止日期",
        type: "DatePicker",
        format:"YYYY-MM-DD",
        disabledDate:"startdate",
        edit: true,
        required: false,
    },
    {
        enname: "creationTime",
        zhname: "订单日期",
        hidepage:{0:true},
        edit: false,
        format:"YYYY-MM-DD",
        type: "DatePicker", 
    },
    {
        enname:"setlatitudeId",
        codename:"setlatitudeCode",
        showname:"setlatitudeName",
        zhname:"设置维度",
        required: true,
        edit:true,
        code:"SZWD",
        type: "Select",
    },
    {
        enname: "cancelName",
        zhname: "制单人",
        type: "FormControl",
        hidepage:{0:true},
        edit: false,
    },
    {
        enname: "show",
        zhname: "备注",
        type: "FormControl",
        pattern:/^\S*$/,
        message: "不能有空格",
        edit: true,
    },
    {
        enname: "ext01",
        zhname: "更新零售状态",
        type: "FormControl",
        edit: false,
    },
];

const columnportrait = [
    {
        title: "标题",
        dataIndex: "filename",
        key: "filename",
        detailwidth: 250,
    }, {
        title: "上传时间",
        dataIndex: "creationTime",
        key: "creationTime",
        detailwidth: 150,
        render: (text, record, index) => {
            return text && ts2Formatter(text,1);
        }
    }, {
        title: "缩略图",
        dataIndex: "fileUrl",
        key: "fileUrl",
        width: 150,
        render: (text, record, index) => {
            if(record.fileUrl.search("jpg") != -1 || record.fileUrl.search("jpeg") != -1 ||record.fileUrl.search("png") != -1){
                return <span>
                <img style={{"width":"35px"}} src={text} />
             </span>
            }else {
                return ""
            }
            
        }
    }, 
    {
        title: "创建人",
        dataIndex: "creator",
        key: "creator",
        width: 150,
    }
]

const columncommissionSon = [
    // {
    //     title: "维度显示",
    //     dataIndex: "dimensionshow",
    //     renderType: "input",
    //     filedProps: {
    //         maxLenght:20,
    //     },
    //     key: "dimensionshow"
    // },
    {
        title: "客户渠道 (不填则默认全渠道)",
        dataIndex: "customerChannelsName",
        key:"customerChannelsName",
        renderType: "refcomponent",
        width: 250,
        hidepage:{0:true,1:true,2:true},
        filedProps: {
            childType: "retailOrderItems",
            title: "渠道",
            constparam:{
                "EQ_enableState": "1",
            },
            refName: "custchantype",
            fieldName: "customerChannelsName",
            reffields: { refpk: "customerChannelsId", refname: "customerChannelsName", refcode: "customerChannelsCode" }
        },
    },
    {
        title: "零售片区",
        dataIndex: "regionName",
        key:"regionName",
        renderType: "refcomponent",
        width: 250,
        hidepage:{0:true,1:true,2:true},
        filedProps: {
            childType: "retailOrderItems",
            title: "零售片区",
            refName: "departmentRef",
            aliasparam: [{
                paramkey: "EQ_organization.id",
                alias: "branchbfficeId",
            }],
            constparam:{
                "EQ_enableState":"0",
            },
            fieldName: "regionName",
            reffields: { refpk: "regionId", refname: "regionName", refcode: "regionCode" }
        },
    },
    {
        title: "门店",
        dataIndex: "storecodeName",
        key:"storecodeName",
        renderType: "refcomponent",
        width: 250,
        hidepage:{0:true,1:true,2:true},
        filedProps: {
            childType: "retailOrderItems",
            title: "门店",
            refName: "terminal",
            aliasparam: [{
                paramkey: "EQ_organization.id",
                alias: "branchbfficeId",
            }],
            fieldName: "storecodeName",
            reffields: { refpk: "storecodeId", refname: "storecodeName", refcode: "storecodeCode" }
        },
    },
    {
        title: "归属客户",
        dataIndex: "ext01Name",
        key:"ext01Name",
        renderType: "refcomponent",
        width: 250,
        hidepage:{0:true,1:true,2:true},
        filedProps: {
            childType: "commissionSon",
            title: "客户",
            refName: "terminalcustomerRef",
            constparam:{
                "EQ_isFrozen": "0"
            },
            aliasparam: [{
                paramkey: "EQ_customerAreas.organization.id",
                alias: "branchbfficeId",
            }],
            fieldName: "ext01Name",
            reffields: { refpk: "ext01Id", refname: "ext01Name", refcode: "ext01Code" }
        },
    },
    {
        title: "品名型号",
        dataIndex: "typenameName",
        key:"typenameName",
        renderType: "refcomponent",
        width: 250,
        validate: false,
        required:true,
        filedProps: {
            childType: "retailOrderItems",
            title: "品名型号",
            refName: "goodsRef",
            fieldName: "typenameName",
            reffields: { refpk: "typenameId", refname: "typenameName", refcode: "typenameCode" }
        },
    },
    {
        title: "目标价",
        dataIndex: "aimvalue",
        key: "aimvalue",
        renderType: "inputnumber",
        filedProps: {
            precision:2,
            min: 0,
        },
        edit: true,
        required: false,
    },
    {
        title: "提成",
        dataIndex: "commission",
        key: "commission",
        width: 120,
        validate: true,
        renderType: "inputnumber",
        required: true,
        filedProps: {
            precision:2,
            // except:0,
            min: 0,
        }
    },
    {
        dataIndex: "show",
        title: "备注",
        renderType: "input",
        pattern:/^\S*$/,
        patternMessage: "不能有空格",
        edit: true,
        required: false,
    }
]
//表单字段

export const FormField = {
    "DataHeader": {
        "title": "基础信息",
        "Field": FormDataHeader
    },
}

//表格弹框表单字段
export const FormTableField = {
}

//渲染成字表表格的头
export const childTableColumn = {
    "commissionSon": {
        "title": "明细",
        "type": "grid",
        "column": columncommissionSon
    },
    "portrait": {
        "title": "附件",
        "type": "grid",
        "column": columnportrait
    },
}

//渲染成字表表格的头
export const mainTableColumn = [
    {
        title: "单据日期",
        dataIndex: "creationTime",
        key: "creationTime",
        width:110,
        render: (text) => {
            return text && ts2Formatter(text);
        }
    },
    {
        title: "审核状态",
        dataIndex: "state",
        key: "state",
        width:100,
        render:(text, record, index)=> {
            return renderState(text);
        }
    },
    {
        title: "单据号",
        dataIndex: "code",
        width:110,
        key: "code",
        render: (text, record) => {
            return <a style={{ "cursor": "pointer" }}
                onClick={() => {
                    actions.routing.push(
                        {
                            pathname: 'PromoterCommission-edit',
                            search: `?search_id=${record.id}&btnPageFlag=2`,
                        }
                    );
                    // location.reload();
                }}
            >
                {text}
            </a >;
        }
    },
    {
        title: "生效日期",
        dataIndex: "startdate",
        width: 150,
        width:110,
        key: "startdate",
        render: (text) => {
            return text && ts2Formatter(text);
        }
    },
    {
        title: "截止日期",
        dataIndex: "enddate",
        width: 110,
        key: "enddate",
        render: (text) => {
            return text && ts2Formatter(text);
        }
    },
    {
        title: "政策类型",
        dataIndex: "policytypeName",
        width: 110,
        key: "policytypeName",
    },
    {
        title: "设置维度",
        dataIndex: "setlatitudeName",
        width: 110,
        key: "setlatitudeName",
    },
    {
        title: "制单人",
        dataIndex: "cancelName",
        width: 110,
        key: "cancelName",
    }
]

export const searchField = [
    {
        enname: "branchbfficeId",
        zhname: "隶属组织",
        multiple:false,
        // realRef:true,
        param:{
            "AUTH_refdim":"saleOrg","AUTH_refcod":"retail_order"
        },
        type: "RefComponent",
        refname:"organization",
        edit:true,
    },
    {
        enname:"state",
        zhname:"审批状态",
        required: false,
        code:"BILL_STATUS",
        type: "Select",
        edit: true
    },
    {
        enname: "startdate",
        zhname: "生效日期",
        required: false,
        type: "RangePicker",
        rangeField: ["startdate", "startdate"],
        edit: true
    },
    {
        enname: "enddate",
        zhname: "截止日期",
        required: false,
        type: "RangePicker",
        rangeField: ["enddate", "enddate"],
        edit: true
    },
    {
        enname: "approveTime",
        zhname: "审批日期",
        required: false,
        type: "RangePicker",
        rangeField: ["approveTime", "approveTime"],
        edit: true
    },
    {
        enname: "creationTime",
        zhname: "订单日期",
        required: false,
        type: "RangePicker",
        rangeField: ["creationTime", "creationTime"],
        edit: true
    },
    {
        enname: "code",
        zhname: "单号",
        required: false,
        searchType: 'like',
        type: "FormControl",
        edit: true
    },
    {
        enname:"policytypeId",
        zhname:"政策类型",
        required: false,
        refname:"ZCLXRef",
        type: "RefComponent",
        edit: true
    },
    {
        enname:"setlatitudeId",
        zhname:"设置维度",
        required: false,
        refname:"SZWDRef",
        type: "RefComponent",
        edit: true,
    },
    {
        enname:"cancelId",
        zhname:"制单人",
        required: false,
        refname:"personRef",
        type:"RefComponent",
        edit: true
    },
    {
        enname:"ext01",
        zhname:"更新零售状态",
        required: false,
        type: "Select",
        options: [
            {
                name: '更新完成', code: "更新完成"
            },
            {
                name: '未更新', code: "未更新"
            },
        ],
        edit: true
    },
    {
        enname:"commissionSon&customerChannelsId",
        zhname:"渠道类型",
        required: false,
        refname:"custchantype",
        param:{
            "EQ_enableState":"2"
        },
        type:"RefComponent",
        edit: true
    },
    {
        enname:"commissionSon&regionId",
        zhname:"零售片区",
        required: false,
        refname:"departmentRef",
        type:"RefComponent",
        edit: true
    },
    {
        enname:"commissionSon&storecodeId",
        zhname:"门店",
        required: false,
        refname:"terminal",
        type:"RefComponent",
        edit: true
    },
    {
        enname:"commissionSon&ext01Id",
        zhname:"归属客户",
        required: false,
        refname:"terminalcustomerRef",
        param:{
            "EQ_isEnable":"1"
        },
        type:"RefComponent",
        edit: true
    },
    {
        enname:"commissionSon&typenameId",
        zhname:"品名型号",
        required: false,
        refname:"goodsRef",
        type:"RefComponent",
        edit: true
    }
]

export const headerButtonSets = [
    {
        event: "ButtonAdd",
        zhname: "新增",
        color: 'primary',
        authcode: "commissionadd",
    }
]

export const columnButtonSets = {
    "delete": {
        event: "ButtonDel",
        zhname: "删除",
        batch: true,
        method: "post",
        ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
        url: 'occ-base/base/promoter-commissions/deleteout'
    },
    "edit": true,
    "detail": true
}

// export default {mainTableColumn,searchField,headerButtonSets,
//     columnButtonSets,childTableColumn,FormTableField,FormField}
export const SelectCode = ["SZWD","ZCLX","BILL_STATUS"]
